package com.detu.ivos.dict.controller;

import com.detu.ivos.base.response.JsonResult;
import com.detu.ivos.dict.pojo.dto.DictQuery;
import com.detu.ivos.dict.pojo.dto.DictSaveParam;
import com.detu.ivos.dict.pojo.vo.DictVO;
import com.detu.ivos.dict.service.DictService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Slf4j
@RestController
@RequestMapping("/v1/dict")
public class DictController {
    @Autowired
    DictService dictService;
    //根据条件查询字典
    @GetMapping("select")
    public JsonResult select(DictQuery dictQuery) {
        log.debug("通过{}查询",dictQuery);
        List<DictVO> dictVOS= dictService.selectDict(dictQuery);
        return JsonResult.ok(dictVOS);
    }

    //添加和更新字典
    @PostMapping("save")
    public JsonResult save(DictSaveParam dictSaveParam){
        log.debug("添加的字典={}",dictSaveParam);
        dictService.savedict(dictSaveParam);
        return JsonResult.ok();
    }
    @PostMapping("delete/{id}")
    public JsonResult deleteDict(@PathVariable Long id) {
        log.debug("删除字典:id={}", id);
        dictService.deleteDict(id);
        return JsonResult.ok();
    }
}
